﻿using System;
using UnityEngine;
using System.Collections;
using UnityEditor;
using UnityEngine.UI;
using UnityEngine.UIElements;

namespace CircularScrollView
{
    [CanEditMultipleObjects,CustomEditor(typeof(CircularScrollView.UICircularScrollView))]
    public class UICircularScrollViewEditor : Editor
    {
        UICircularScrollView list;
        private int m_childCount=0;
        private Transform m_content;

        public void OnEnable()
        {
            Debug.Log("UICircularScrollViewEditor.OnEnable");
            // m_childCount=0;
        }

        public override void OnInspectorGUI()
        {
            list = (CircularScrollView.UICircularScrollView)target;
            
            list.direction = (e_Direction)EditorGUILayout.EnumPopup("Direction: ", list.direction);
            list.row = EditorGUILayout.IntField("Row Or Column: ", list.row);
            list.spacing = EditorGUILayout.FloatField("Spacing: ", list.spacing);
            if (list.row>1)
            {
                list.spacingVer = EditorGUILayout.FloatField("SpacingVer: ", list.spacingVer);
            }
            
            list.scrollViewCell = (ScrollViewCell)EditorGUILayout.ObjectField("Cell: ", list.scrollViewCell, typeof(ScrollViewCell), true);
            list.isShowArrow = EditorGUILayout.ToggleLeft(" IsShowArrow", list.isShowArrow);
            if(list.isShowArrow)
            {
                list.pointingFirstArrow = (GameObject)EditorGUILayout.ObjectField("Up or Left Arrow: ", list.pointingFirstArrow, typeof(GameObject), true);
                list.pointingEndArrow = (GameObject)EditorGUILayout.ObjectField("Down or Right Arrow: ", list.pointingEndArrow, typeof(GameObject), true);
            }
            
            //判断list是否更改，有更改则保存
            if (GUI.changed)
                EditorUtility.SetDirty(list);           {
            }
        }

        private void OnLayoutChange()
        {
            if(list==null)
                return;
            
            if (m_content==null)
            {
                m_content = list.transform.GetComponent<ScrollRect>().content;
            }

            for (int i = 0; i < m_content.transform.childCount; i++)
            {
                
            }
        }
    }
}